﻿using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Project.Net.Application.User;
using Project.Net.Domain;
using Project.Net.Filters;
using Project.Net.Request;
using Project.Net.Response;

namespace Project.Net.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    [ApiResult]
    [TypeFilter(typeof(GlobalExceptionFilter))]
    public class UserController : ControllerBase
    {
        private readonly IUserLoginService _userLoginService;
        public UserController(IUserLoginService userLoginService)
        {
            _userLoginService = userLoginService;
        }

        /// <summary>
        /// 登录
        /// </summary>
        /// <param name="username"></param>  
        /// <param name="password"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<string> Login(UserLoginRequest request)
        {
            var token= await _userLoginService.Login(request.UserName, request.Password);
            return token;
        }

        /// <summary>
        /// 注册用户
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<bool> RequestUser(RegisterUserRequest request)
        {
            var user = await _userLoginService.AddUser(request.UserName, request.PasswordHash, request.Email);
            return true;
        }
    }
}
